<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>structs_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_structs_structs_test.js.html">structs_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.structsTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.structsTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.array&#39;);
<a name="line19"></a>goog.require(&#39;goog.structs&#39;);
<a name="line20"></a>goog.require(&#39;goog.structs.Map&#39;);
<a name="line21"></a>goog.require(&#39;goog.structs.Set&#39;);  // needed for filter
<a name="line22"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line23"></a>
<a name="line24"></a>/*
<a name="line25"></a>
<a name="line26"></a> This one does not test Map or Set
<a name="line27"></a> It tests Array, Object, String and a NodeList
<a name="line28"></a>
<a name="line29"></a>*/
<a name="line30"></a>
<a name="line31"></a>
<a name="line32"></a>
<a name="line33"></a>function stringifyObject(obj) {
<a name="line34"></a>  var sb = [];
<a name="line35"></a>  for (var key in obj) {
<a name="line36"></a>    sb.push(key + obj[key]);
<a name="line37"></a>  }
<a name="line38"></a>  return sb.join(&#39;&#39;);
<a name="line39"></a>}
<a name="line40"></a>
<a name="line41"></a>
<a name="line42"></a>function getTestElement() {
<a name="line43"></a>  return document.getElementById(&#39;test&#39;);
<a name="line44"></a>}
<a name="line45"></a>
<a name="line46"></a>
<a name="line47"></a>function getAll() {
<a name="line48"></a>  return getTestElement().getElementsByTagName(&#39;*&#39;);
<a name="line49"></a>}
<a name="line50"></a>
<a name="line51"></a>
<a name="line52"></a>var node;
<a name="line53"></a>
<a name="line54"></a>
<a name="line55"></a>function addNode() {
<a name="line56"></a>  node = document.createElement(&#39;span&#39;);
<a name="line57"></a>  getTestElement().appendChild(node);
<a name="line58"></a>}
<a name="line59"></a>
<a name="line60"></a>
<a name="line61"></a>function removeNode() {
<a name="line62"></a>  getTestElement().removeChild(node);
<a name="line63"></a>}
<a name="line64"></a>
<a name="line65"></a>
<a name="line66"></a>function nodeNames(nl) {
<a name="line67"></a>  var sb = [];
<a name="line68"></a>  for (var i = 0, n; n = nl[i]; i++) {
<a name="line69"></a>    sb.push(n.nodeName.toLowerCase());
<a name="line70"></a>  }
<a name="line71"></a>  return sb.join(&#39;,&#39;);
<a name="line72"></a>}
<a name="line73"></a>
<a name="line74"></a>
<a name="line75"></a>var allTagNames1 = &#39;hr,p,p,p,p,p,p,p,p,h1&#39;;
<a name="line76"></a>var allTagNames2 = allTagNames1 + &#39;,span&#39;;
<a name="line77"></a>
<a name="line78"></a>
<a name="line79"></a>function testGetCount() {
<a name="line80"></a>  var arr = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;];
<a name="line81"></a>  assertEquals(&#39;count, should be 3&#39;, 3, goog.structs.getCount(arr));
<a name="line82"></a>  arr.push(&#39;d&#39;);
<a name="line83"></a>  assertEquals(&#39;count, should be 4&#39;, 4, goog.structs.getCount(arr));
<a name="line84"></a>  goog.array.remove(arr, &#39;d&#39;);
<a name="line85"></a>  assertEquals(&#39;count, should be 3&#39;, 3, goog.structs.getCount(arr));
<a name="line86"></a>
<a name="line87"></a>  var obj = {a: 0, b: 1, c: 2};
<a name="line88"></a>  assertEquals(&#39;count, should be 3&#39;, 3, goog.structs.getCount(obj));
<a name="line89"></a>  obj.d = 3;
<a name="line90"></a>  assertEquals(&#39;count, should be 4&#39;, 4, goog.structs.getCount(obj));
<a name="line91"></a>  delete obj.d;
<a name="line92"></a>  assertEquals(&#39;count, should be 3&#39;, 3, goog.structs.getCount(obj));
<a name="line93"></a>
<a name="line94"></a>  var s = &#39;abc&#39;;
<a name="line95"></a>  assertEquals(&#39;count, should be 3&#39;, 3, goog.structs.getCount(s));
<a name="line96"></a>  s += &#39;d&#39;;
<a name="line97"></a>  assertEquals(&#39;count, should be 4&#39;, 4, goog.structs.getCount(s));
<a name="line98"></a>
<a name="line99"></a>  var all = getAll();
<a name="line100"></a>  assertEquals(&#39;count, should be 10&#39;, 10, goog.structs.getCount(all));
<a name="line101"></a>  addNode();
<a name="line102"></a>  assertEquals(&#39;count, should be 11&#39;, 11, goog.structs.getCount(all));
<a name="line103"></a>  removeNode();
<a name="line104"></a>  assertEquals(&#39;count, should be 10&#39;, 10, goog.structs.getCount(all));
<a name="line105"></a>
<a name="line106"></a>  var aMap = new goog.structs.Map({a: 0, b: 1, c: 2});
<a name="line107"></a>  assertEquals(&#39;count, should be 3&#39;, 3, goog.structs.getCount(aMap));
<a name="line108"></a>  aMap.set(&#39;d&#39;, 3);
<a name="line109"></a>  assertEquals(&#39;count, should be 4&#39;, 4, goog.structs.getCount(aMap));
<a name="line110"></a>  aMap.remove(&#39;a&#39;);
<a name="line111"></a>  assertEquals(&#39;count, should be 3&#39;, 3, goog.structs.getCount(aMap));
<a name="line112"></a>
<a name="line113"></a>  var aSet = new goog.structs.Set(&#39;abc&#39;);
<a name="line114"></a>  assertEquals(&#39;count, should be 3&#39;, 3, goog.structs.getCount(aSet));
<a name="line115"></a>  aSet.add(&#39;d&#39;);
<a name="line116"></a>  assertEquals(&#39;count, should be 4&#39;, 4, goog.structs.getCount(aSet));
<a name="line117"></a>  aSet.remove(&#39;a&#39;);
<a name="line118"></a>  assertEquals(&#39;count, should be 3&#39;, 3, goog.structs.getCount(aSet));
<a name="line119"></a>}
<a name="line120"></a>
<a name="line121"></a>
<a name="line122"></a>function testGetValues() {
<a name="line123"></a>  var arr = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;];
<a name="line124"></a>  assertEquals(&#39;abcd&#39;, goog.structs.getValues(arr).join(&#39;&#39;));
<a name="line125"></a>
<a name="line126"></a>  var obj = {a: 0, b: 1, c: 2, d: 3};
<a name="line127"></a>  assertEquals(&#39;0123&#39;, goog.structs.getValues(obj).join(&#39;&#39;));
<a name="line128"></a>
<a name="line129"></a>  var s = &#39;abc&#39;;
<a name="line130"></a>  assertEquals(&#39;abc&#39;, goog.structs.getValues(s).join(&#39;&#39;));
<a name="line131"></a>  s += &#39;d&#39;;
<a name="line132"></a>  assertEquals(&#39;abcd&#39;, goog.structs.getValues(s).join(&#39;&#39;));
<a name="line133"></a>
<a name="line134"></a>  var all = getAll();
<a name="line135"></a>  assertEquals(allTagNames1, nodeNames(goog.structs.getValues(all)));
<a name="line136"></a>  addNode();
<a name="line137"></a>  assertEquals(allTagNames2, nodeNames(goog.structs.getValues(all)));
<a name="line138"></a>  removeNode();
<a name="line139"></a>  assertEquals(allTagNames1, nodeNames(goog.structs.getValues(all)));
<a name="line140"></a>
<a name="line141"></a>  var aMap = new goog.structs.Map({a: 1, b: 2, c: 3});
<a name="line142"></a>  assertEquals(&#39;123&#39;, goog.structs.getValues(aMap).join(&#39;&#39;));
<a name="line143"></a>
<a name="line144"></a>  var aSet = new goog.structs.Set([1, 2, 3]);
<a name="line145"></a>  assertEquals(&#39;123&#39;, goog.structs.getValues(aMap).join(&#39;&#39;));
<a name="line146"></a>}
<a name="line147"></a>
<a name="line148"></a>
<a name="line149"></a>function testGetKeys() {
<a name="line150"></a>  var arr = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;];
<a name="line151"></a>  assertEquals(&#39;0123&#39;, goog.structs.getKeys(arr).join(&#39;&#39;));
<a name="line152"></a>
<a name="line153"></a>  var obj = {a: 0, b: 1, c: 2, d: 3};
<a name="line154"></a>  assertEquals(&#39;abcd&#39;, goog.structs.getKeys(obj).join(&#39;&#39;));
<a name="line155"></a>
<a name="line156"></a>  var s = &#39;abc&#39;;
<a name="line157"></a>  assertEquals(&#39;012&#39;, goog.structs.getKeys(s).join(&#39;&#39;));
<a name="line158"></a>  s += &#39;d&#39;;
<a name="line159"></a>  assertEquals(&#39;0123&#39;, goog.structs.getKeys(s).join(&#39;&#39;));
<a name="line160"></a>
<a name="line161"></a>  var all = getAll();
<a name="line162"></a>  assertEquals(&#39;0123456789&#39;, goog.structs.getKeys(all).join(&#39;&#39;));
<a name="line163"></a>  addNode();
<a name="line164"></a>  assertEquals(&#39;012345678910&#39;, goog.structs.getKeys(all).join(&#39;&#39;));
<a name="line165"></a>  removeNode();
<a name="line166"></a>  assertEquals(&#39;0123456789&#39;, goog.structs.getKeys(all).join(&#39;&#39;));
<a name="line167"></a>
<a name="line168"></a>  var aMap = new goog.structs.Map({a: 1, b: 2, c: 3});
<a name="line169"></a>  assertEquals(&#39;abc&#39;, goog.structs.getKeys(aMap).join(&#39;&#39;));
<a name="line170"></a>
<a name="line171"></a>  var aSet = new goog.structs.Set([1, 2, 3]);
<a name="line172"></a>  assertUndefined(goog.structs.getKeys(aSet));
<a name="line173"></a>}
<a name="line174"></a>
<a name="line175"></a>function testContains() {
<a name="line176"></a>  var arr = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;];
<a name="line177"></a>  assertTrue(&quot;contains, Should contain &#39;a&#39;&quot;, goog.structs.contains(arr, &#39;a&#39;));
<a name="line178"></a>  assertFalse(
<a name="line179"></a>      &quot;contains, Should not contain &#39;e&#39;&quot;, goog.structs.contains(arr, &#39;e&#39;));
<a name="line180"></a>
<a name="line181"></a>  var obj = {a: 0, b: 1, c: 2, d: 3};
<a name="line182"></a>  assertTrue(&quot;contains, Should contain &#39;0&#39;&quot;, goog.structs.contains(obj, 0));
<a name="line183"></a>  assertFalse(
<a name="line184"></a>      &quot;contains, Should not contain &#39;4&#39;&quot;, goog.structs.contains(obj, 4));
<a name="line185"></a>
<a name="line186"></a>  var s = &#39;abc&#39;;
<a name="line187"></a>  assertTrue(&quot;contains, Should contain &#39;a&#39;&quot;, goog.structs.contains(s, &#39;a&#39;));
<a name="line188"></a>  assertFalse(
<a name="line189"></a>      &quot;contains, Should not contain &#39;d&#39;&quot;, goog.structs.contains(s, &#39;d&#39;));
<a name="line190"></a>
<a name="line191"></a>  var all = getAll();
<a name="line192"></a>  assertTrue(&quot;contains, Should contain &#39;h1&#39;&quot;,
<a name="line193"></a>             goog.structs.contains(all, document.getElementById(&#39;h1&#39;)));
<a name="line194"></a>  assertFalse(&quot;contains, Should not contain &#39;document.body&#39;&quot;,
<a name="line195"></a>              goog.structs.contains(all, document.body));
<a name="line196"></a>
<a name="line197"></a>  var aMap = new goog.structs.Map({a: 1, b: 2, c: 3});
<a name="line198"></a>  assertTrue(&quot;contains, Should contain &#39;1&#39;&quot;, goog.structs.contains(aMap, 1));
<a name="line199"></a>  assertFalse(
<a name="line200"></a>      &quot;contains, Should not contain &#39;4&#39;&quot;, goog.structs.contains(aMap, 4));
<a name="line201"></a>
<a name="line202"></a>  var aSet = new goog.structs.Set([1, 2, 3]);
<a name="line203"></a>  assertTrue(&quot;contains, Should contain &#39;1&#39;&quot;, goog.structs.contains(aSet, 1));
<a name="line204"></a>  assertFalse(
<a name="line205"></a>      &quot;contains, Should not contain &#39;4&#39;&quot;, goog.structs.contains(aSet, 4));
<a name="line206"></a>}
<a name="line207"></a>
<a name="line208"></a>
<a name="line209"></a>function testClear() {
<a name="line210"></a>  var arr = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;];
<a name="line211"></a>  goog.structs.clear(arr);
<a name="line212"></a>  assertTrue(&#39;cleared so it should be empty&#39;, goog.structs.isEmpty(arr));
<a name="line213"></a>  assertFalse(
<a name="line214"></a>      &quot;cleared so it should not contain &#39;a&#39;&quot;, goog.structs.contains(arr, &#39;a&#39;));
<a name="line215"></a>
<a name="line216"></a>  var obj = {a: 0, b: 1, c: 2, d: 3};
<a name="line217"></a>  goog.structs.clear(obj);
<a name="line218"></a>  assertTrue(&#39;cleared so it should be empty&#39;, goog.structs.isEmpty(obj));
<a name="line219"></a>  assertFalse(
<a name="line220"></a>      &quot;cleared so it should not contain &#39;a&#39; key&quot;,
<a name="line221"></a>      goog.structs.contains(obj, 0));
<a name="line222"></a>
<a name="line223"></a>  var aMap = new goog.structs.Map({a: 1, b: 2, c: 3});
<a name="line224"></a>  goog.structs.clear(aMap);
<a name="line225"></a>  assertTrue(&#39;cleared map so it should be empty&#39;, goog.structs.isEmpty(aMap));
<a name="line226"></a>  assertFalse(&quot;cleared map so it should not contain &#39;1&#39; value&quot;,
<a name="line227"></a>      goog.structs.contains(aMap, 1));
<a name="line228"></a>
<a name="line229"></a>  var aSet = new goog.structs.Set([1, 2, 3]);
<a name="line230"></a>  goog.structs.clear(aSet);
<a name="line231"></a>  assertTrue(&#39;cleared set so it should be empty&#39;, goog.structs.isEmpty(aSet));
<a name="line232"></a>  assertFalse(
<a name="line233"></a>      &quot;cleared set so it should not contain &#39;1&#39;&quot;,
<a name="line234"></a>      goog.structs.contains(aSet, 1));
<a name="line235"></a>
<a name="line236"></a>  // cannot clear a string or a NodeList
<a name="line237"></a>}
<a name="line238"></a>
<a name="line239"></a>
<a name="line240"></a>
<a name="line241"></a>// Map
<a name="line242"></a>
<a name="line243"></a>function testMap() {
<a name="line244"></a>  var RV = {};
<a name="line245"></a>  var obj = {
<a name="line246"></a>    map: function(g) {
<a name="line247"></a>      assertEquals(f, g);
<a name="line248"></a>      assertEquals(this, obj);
<a name="line249"></a>      return RV;
<a name="line250"></a>    }
<a name="line251"></a>  };
<a name="line252"></a>  function f() {}
<a name="line253"></a>  assertEquals(RV, goog.structs.map(obj, f));
<a name="line254"></a>}
<a name="line255"></a>
<a name="line256"></a>function testMap2() {
<a name="line257"></a>  var THIS_OBJ = {};
<a name="line258"></a>  var RV = {};
<a name="line259"></a>  var obj = {
<a name="line260"></a>    map: function(g, obj2) {
<a name="line261"></a>      assertEquals(f, g);
<a name="line262"></a>      assertEquals(this, obj);
<a name="line263"></a>      assertEquals(THIS_OBJ, obj2);
<a name="line264"></a>      return RV;
<a name="line265"></a>    }
<a name="line266"></a>  };
<a name="line267"></a>  function f() {}
<a name="line268"></a>  assertEquals(RV, goog.structs.map(obj, f, THIS_OBJ));
<a name="line269"></a>}
<a name="line270"></a>
<a name="line271"></a>function testMapArrayLike() {
<a name="line272"></a>  var col = [0, 1, 2];
<a name="line273"></a>  function f(v, i, col2) {
<a name="line274"></a>    assertEquals(col, col2);
<a name="line275"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line276"></a>    return v * v;
<a name="line277"></a>  }
<a name="line278"></a>  assertArrayEquals([0, 1, 4], goog.structs.map(col, f));
<a name="line279"></a>}
<a name="line280"></a>
<a name="line281"></a>function testMapArrayLike2() {
<a name="line282"></a>  var THIS_OBJ = {};
<a name="line283"></a>  var col = [0, 1, 2];
<a name="line284"></a>  function f(v, i, col2) {
<a name="line285"></a>    assertEquals(col, col2);
<a name="line286"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line287"></a>    assertEquals(THIS_OBJ, this);
<a name="line288"></a>    return v * v;
<a name="line289"></a>  }
<a name="line290"></a>  assertArrayEquals([0, 1, 4], goog.structs.map(col, f, THIS_OBJ));
<a name="line291"></a>}
<a name="line292"></a>
<a name="line293"></a>function testMapString() {
<a name="line294"></a>  var col = &#39;012&#39;;
<a name="line295"></a>  function f(v, i, col2) {
<a name="line296"></a>    // Teh SpiderMonkey Array.map for strings turns the string into a String
<a name="line297"></a>    // so we cannot use assertEquals because it uses ===.
<a name="line298"></a>    assertTrue(col == col2);
<a name="line299"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line300"></a>    return Number(v) * Number(v);
<a name="line301"></a>  }
<a name="line302"></a>  assertArrayEquals([0, 1, 4], goog.structs.map(col, f));
<a name="line303"></a>}
<a name="line304"></a>
<a name="line305"></a>function testMapString2() {
<a name="line306"></a>  var THIS_OBJ = {};
<a name="line307"></a>  var col = &#39;012&#39;;
<a name="line308"></a>  function f(v, i, col2) {
<a name="line309"></a>    // for some reason the strings are equal but identical???
<a name="line310"></a>    assertEquals(String(col), String(col2));
<a name="line311"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line312"></a>    assertEquals(THIS_OBJ, this);
<a name="line313"></a>    return Number(v) * Number(v);
<a name="line314"></a>  }
<a name="line315"></a>  assertArrayEquals([0, 1, 4], goog.structs.map(col, f, THIS_OBJ));
<a name="line316"></a>}
<a name="line317"></a>
<a name="line318"></a>function testMapMap() {
<a name="line319"></a>  var col = new goog.structs.Map({a: 0, b: 1, c: 2});
<a name="line320"></a>  function f(v, key, col2) {
<a name="line321"></a>    assertEquals(col, col2);
<a name="line322"></a>    assertEquals(&#39;string&#39;, typeof key);
<a name="line323"></a>    return v * v;
<a name="line324"></a>  }
<a name="line325"></a>  assertObjectEquals({a: 0, b: 1, c: 4}, goog.structs.map(col, f));
<a name="line326"></a>}
<a name="line327"></a>
<a name="line328"></a>function testMapMap2() {
<a name="line329"></a>  var THIS_OBJ = {};
<a name="line330"></a>  var col = new goog.structs.Map({a: 0, b: 1, c: 2});
<a name="line331"></a>  function f(v, key, col2) {
<a name="line332"></a>    assertEquals(col, col2);
<a name="line333"></a>    assertEquals(&#39;string&#39;, typeof key);
<a name="line334"></a>    assertEquals(THIS_OBJ, this);
<a name="line335"></a>    return v * v;
<a name="line336"></a>  }
<a name="line337"></a>  assertObjectEquals({a: 0, b: 1, c: 4}, goog.structs.map(col, f, THIS_OBJ));
<a name="line338"></a>}
<a name="line339"></a>
<a name="line340"></a>function testMapSet() {
<a name="line341"></a>  var col = new goog.structs.Set([0, 1, 2]);
<a name="line342"></a>  function f(v, key, col2) {
<a name="line343"></a>    assertEquals(col, col2);
<a name="line344"></a>    assertEquals(&#39;undefined&#39;, typeof key);
<a name="line345"></a>    return v * v;
<a name="line346"></a>  }
<a name="line347"></a>  assertArrayEquals([0, 1, 4], goog.structs.map(col, f));
<a name="line348"></a>}
<a name="line349"></a>
<a name="line350"></a>function testMapSet2() {
<a name="line351"></a>  var THIS_OBJ = {};
<a name="line352"></a>  var col = new goog.structs.Set([0, 1, 2]);
<a name="line353"></a>  function f(v, key, col2) {
<a name="line354"></a>    assertEquals(col, col2);
<a name="line355"></a>    assertEquals(&#39;undefined&#39;, typeof key);
<a name="line356"></a>    assertEquals(THIS_OBJ, this);
<a name="line357"></a>    return v * v;
<a name="line358"></a>  }
<a name="line359"></a>  assertArrayEquals([0, 1, 4], goog.structs.map(col, f, THIS_OBJ));
<a name="line360"></a>}
<a name="line361"></a>
<a name="line362"></a>function testMapNodeList() {
<a name="line363"></a>  var col = getAll();
<a name="line364"></a>  function f(v, i, col2) {
<a name="line365"></a>    assertEquals(col, col2);
<a name="line366"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line367"></a>    return v.tagName;
<a name="line368"></a>  }
<a name="line369"></a>  assertEquals(&#39;HRPPPPPPPPH1&#39;, goog.structs.map(col, f).join(&#39;&#39;));
<a name="line370"></a>}
<a name="line371"></a>
<a name="line372"></a>function testMapNodeList2() {
<a name="line373"></a>  var THIS_OBJ = {};
<a name="line374"></a>  var col = getAll();
<a name="line375"></a>  function f(v, i, col2) {
<a name="line376"></a>    assertEquals(col, col2);
<a name="line377"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line378"></a>    assertEquals(THIS_OBJ, this);
<a name="line379"></a>    return v.tagName;
<a name="line380"></a>  }
<a name="line381"></a>  assertEquals(&#39;HRPPPPPPPPH1&#39;, goog.structs.map(col, f, THIS_OBJ).join(&#39;&#39;));
<a name="line382"></a>}
<a name="line383"></a>
<a name="line384"></a>// Filter
<a name="line385"></a>
<a name="line386"></a>function testFilter() {
<a name="line387"></a>  var RV = {};
<a name="line388"></a>  var obj = {
<a name="line389"></a>    filter: function(g) {
<a name="line390"></a>      assertEquals(f, g);
<a name="line391"></a>      assertEquals(this, obj);
<a name="line392"></a>      return RV;
<a name="line393"></a>    }
<a name="line394"></a>  };
<a name="line395"></a>  function f() {}
<a name="line396"></a>  assertEquals(RV, goog.structs.filter(obj, f));
<a name="line397"></a>}
<a name="line398"></a>
<a name="line399"></a>function testFilter2() {
<a name="line400"></a>  var THIS_OBJ = {};
<a name="line401"></a>  var RV = {};
<a name="line402"></a>  var obj = {
<a name="line403"></a>    filter: function(g, obj2) {
<a name="line404"></a>      assertEquals(f, g);
<a name="line405"></a>      assertEquals(this, obj);
<a name="line406"></a>      assertEquals(THIS_OBJ, obj2);
<a name="line407"></a>      return RV;
<a name="line408"></a>    }
<a name="line409"></a>  };
<a name="line410"></a>  function f() {}
<a name="line411"></a>  assertEquals(RV, goog.structs.filter(obj, f, THIS_OBJ));
<a name="line412"></a>}
<a name="line413"></a>
<a name="line414"></a>function testFilterArrayLike() {
<a name="line415"></a>  var col = [0, 1, 2];
<a name="line416"></a>  function f(v, i, col2) {
<a name="line417"></a>    assertEquals(col, col2);
<a name="line418"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line419"></a>    return v &gt; 0;
<a name="line420"></a>  }
<a name="line421"></a>  assertArrayEquals([1, 2], goog.structs.filter(col, f));
<a name="line422"></a>}
<a name="line423"></a>
<a name="line424"></a>function testFilterArrayLike2() {
<a name="line425"></a>  var THIS_OBJ = {};
<a name="line426"></a>  var col = [0, 1, 2];
<a name="line427"></a>  function f(v, i, col2) {
<a name="line428"></a>    assertEquals(col, col2);
<a name="line429"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line430"></a>    assertEquals(THIS_OBJ, this);
<a name="line431"></a>    return v &gt; 0;
<a name="line432"></a>  }
<a name="line433"></a>  assertArrayEquals([1, 2], goog.structs.filter(col, f, THIS_OBJ));
<a name="line434"></a>}
<a name="line435"></a>
<a name="line436"></a>function testFilterString() {
<a name="line437"></a>  var col = &#39;012&#39;;
<a name="line438"></a>  function f(v, i, col2) {
<a name="line439"></a>    // for some reason the strings are equal but identical???
<a name="line440"></a>    assertEquals(String(col), String(col2));
<a name="line441"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line442"></a>    return Number(v) &gt; 0;
<a name="line443"></a>  }
<a name="line444"></a>  assertArrayEquals([&#39;1&#39;, &#39;2&#39;], goog.structs.filter(col, f));
<a name="line445"></a>}
<a name="line446"></a>
<a name="line447"></a>function testFilterString2() {
<a name="line448"></a>  var THIS_OBJ = {};
<a name="line449"></a>  var col = &#39;012&#39;;
<a name="line450"></a>  function f(v, i, col2) {
<a name="line451"></a>    // for some reason the strings are equal but identical???
<a name="line452"></a>    assertEquals(String(col), String(col2));
<a name="line453"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line454"></a>    assertEquals(THIS_OBJ, this);
<a name="line455"></a>    return Number(v) &gt; 0;
<a name="line456"></a>  }
<a name="line457"></a>  assertArrayEquals([&#39;1&#39;, &#39;2&#39;], goog.structs.filter(col, f, THIS_OBJ));
<a name="line458"></a>}
<a name="line459"></a>
<a name="line460"></a>function testFilterMap() {
<a name="line461"></a>  var col = new goog.structs.Map({a: 0, b: 1, c: 2});
<a name="line462"></a>  function f(v, key, col2) {
<a name="line463"></a>    assertEquals(col, col2);
<a name="line464"></a>    assertEquals(&#39;string&#39;, typeof key);
<a name="line465"></a>    return v &gt; 0;
<a name="line466"></a>  }
<a name="line467"></a>  assertObjectEquals({b: 1, c: 2}, goog.structs.filter(col, f));
<a name="line468"></a>}
<a name="line469"></a>
<a name="line470"></a>function testFilterMap2() {
<a name="line471"></a>  var THIS_OBJ = {};
<a name="line472"></a>  var col = new goog.structs.Map({a: 0, b: 1, c: 2});
<a name="line473"></a>  function f(v, key, col2) {
<a name="line474"></a>    assertEquals(col, col2);
<a name="line475"></a>    assertEquals(&#39;string&#39;, typeof key);
<a name="line476"></a>    assertEquals(THIS_OBJ, this);
<a name="line477"></a>    return v &gt; 0;
<a name="line478"></a>  }
<a name="line479"></a>  assertObjectEquals({b: 1, c: 2}, goog.structs.filter(col, f, THIS_OBJ));
<a name="line480"></a>}
<a name="line481"></a>
<a name="line482"></a>function testFilterSet() {
<a name="line483"></a>  var col = new goog.structs.Set([0, 1, 2]);
<a name="line484"></a>  function f(v, key, col2) {
<a name="line485"></a>    assertEquals(col, col2);
<a name="line486"></a>    assertEquals(&#39;undefined&#39;, typeof key);
<a name="line487"></a>    return v &gt; 0;
<a name="line488"></a>  }
<a name="line489"></a>  assertArrayEquals([1, 2], goog.structs.filter(col, f));
<a name="line490"></a>}
<a name="line491"></a>
<a name="line492"></a>function testFilterSet2() {
<a name="line493"></a>  var THIS_OBJ = {};
<a name="line494"></a>  var col = new goog.structs.Set([0, 1, 2]);
<a name="line495"></a>  function f(v, key, col2) {
<a name="line496"></a>    assertEquals(col, col2);
<a name="line497"></a>    assertEquals(&#39;undefined&#39;, typeof key);
<a name="line498"></a>    assertEquals(THIS_OBJ, this);
<a name="line499"></a>    return v &gt; 0;
<a name="line500"></a>  }
<a name="line501"></a>  assertArrayEquals([1, 2], goog.structs.filter(col, f, THIS_OBJ));
<a name="line502"></a>}
<a name="line503"></a>
<a name="line504"></a>function testFilterNodeList() {
<a name="line505"></a>  var col = getAll();
<a name="line506"></a>  function f(v, i, col2) {
<a name="line507"></a>    assertEquals(col, col2);
<a name="line508"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line509"></a>    return v.tagName == &#39;P&#39;;
<a name="line510"></a>  }
<a name="line511"></a>  assertEquals(&#39;p,p,p,p,p,p,p,p&#39;,
<a name="line512"></a>               nodeNames(goog.structs.filter(col, f)));
<a name="line513"></a>}
<a name="line514"></a>
<a name="line515"></a>function testFilterNodeList2() {
<a name="line516"></a>  var THIS_OBJ = {};
<a name="line517"></a>  var col = getAll();
<a name="line518"></a>  function f(v, i, col2) {
<a name="line519"></a>    assertEquals(col, col2);
<a name="line520"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line521"></a>    assertEquals(THIS_OBJ, this);
<a name="line522"></a>    return v.tagName == &#39;P&#39;;
<a name="line523"></a>  }
<a name="line524"></a>  assertEquals(&#39;p,p,p,p,p,p,p,p&#39;,
<a name="line525"></a>               nodeNames(goog.structs.filter(col, f, THIS_OBJ)));
<a name="line526"></a>}
<a name="line527"></a>
<a name="line528"></a>// Some
<a name="line529"></a>
<a name="line530"></a>function testSome() {
<a name="line531"></a>  var RV = {};
<a name="line532"></a>  var obj = {
<a name="line533"></a>    some: function(g) {
<a name="line534"></a>      assertEquals(f, g);
<a name="line535"></a>      assertEquals(this, obj);
<a name="line536"></a>      return RV;
<a name="line537"></a>    }
<a name="line538"></a>  };
<a name="line539"></a>  function f() {}
<a name="line540"></a>  assertEquals(RV, goog.structs.some(obj, f));
<a name="line541"></a>}
<a name="line542"></a>
<a name="line543"></a>function testSome2() {
<a name="line544"></a>  var THIS_OBJ = {};
<a name="line545"></a>  var RV = {};
<a name="line546"></a>  var obj = {
<a name="line547"></a>    some: function(g, obj2) {
<a name="line548"></a>      assertEquals(f, g);
<a name="line549"></a>      assertEquals(this, obj);
<a name="line550"></a>      assertEquals(THIS_OBJ, obj2);
<a name="line551"></a>      return RV;
<a name="line552"></a>    }
<a name="line553"></a>  };
<a name="line554"></a>  function f() {}
<a name="line555"></a>  assertEquals(RV, goog.structs.some(obj, f, THIS_OBJ));
<a name="line556"></a>}
<a name="line557"></a>
<a name="line558"></a>function testSomeArrayLike() {
<a name="line559"></a>  var limit = 0;
<a name="line560"></a>  var col = [0, 1, 2];
<a name="line561"></a>  function f(v, i, col2) {
<a name="line562"></a>    assertEquals(col, col2);
<a name="line563"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line564"></a>    return v &gt; limit;
<a name="line565"></a>  }
<a name="line566"></a>  assertTrue(goog.structs.some(col, f));
<a name="line567"></a>  limit = 2;
<a name="line568"></a>  assertFalse(goog.structs.some(col, f));
<a name="line569"></a>}
<a name="line570"></a>
<a name="line571"></a>function testSomeArrayLike2() {
<a name="line572"></a>  var THIS_OBJ = {};
<a name="line573"></a>  var limit = 0;
<a name="line574"></a>  var col = [0, 1, 2];
<a name="line575"></a>  function f(v, i, col2) {
<a name="line576"></a>    assertEquals(col, col2);
<a name="line577"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line578"></a>    assertEquals(THIS_OBJ, this);
<a name="line579"></a>    return v &gt; limit;
<a name="line580"></a>  }
<a name="line581"></a>  assertTrue(goog.structs.some(col, f, THIS_OBJ));
<a name="line582"></a>  limit = 2;
<a name="line583"></a>  assertFalse(goog.structs.some(col, f, THIS_OBJ));
<a name="line584"></a>}
<a name="line585"></a>
<a name="line586"></a>function testSomeString() {
<a name="line587"></a>  var limit = 0;
<a name="line588"></a>  var col = &#39;012&#39;;
<a name="line589"></a>  function f(v, i, col2) {
<a name="line590"></a>    // for some reason the strings are equal but identical???
<a name="line591"></a>    assertEquals(String(col), String(col2));
<a name="line592"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line593"></a>    return Number(v) &gt; limit;
<a name="line594"></a>  }
<a name="line595"></a>  assertTrue(goog.structs.some(col, f));
<a name="line596"></a>  limit = 2;
<a name="line597"></a>  assertFalse(goog.structs.some(col, f));
<a name="line598"></a>}
<a name="line599"></a>
<a name="line600"></a>function testSomeString2() {
<a name="line601"></a>  var THIS_OBJ = {};
<a name="line602"></a>  var limit = 0;
<a name="line603"></a>  var col = &#39;012&#39;;
<a name="line604"></a>  function f(v, i, col2) {
<a name="line605"></a>    // for some reason the strings are equal but identical???
<a name="line606"></a>    assertEquals(String(col), String(col2));
<a name="line607"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line608"></a>    assertEquals(THIS_OBJ, this);
<a name="line609"></a>    return Number(v) &gt; limit;
<a name="line610"></a>  }
<a name="line611"></a>  assertTrue(goog.structs.some(col, f, THIS_OBJ));
<a name="line612"></a>  limit = 2;
<a name="line613"></a>  assertFalse(goog.structs.some(col, f, THIS_OBJ));
<a name="line614"></a>}
<a name="line615"></a>
<a name="line616"></a>function testSomeMap() {
<a name="line617"></a>  var limit = 0;
<a name="line618"></a>  var col = new goog.structs.Map({a: 0, b: 1, c: 2});
<a name="line619"></a>  function f(v, key, col2) {
<a name="line620"></a>    assertEquals(col, col2);
<a name="line621"></a>    assertEquals(&#39;string&#39;, typeof key);
<a name="line622"></a>    return v &gt; limit;
<a name="line623"></a>  }
<a name="line624"></a>  assertObjectEquals(true, goog.structs.some(col, f));
<a name="line625"></a>  limit = 2;
<a name="line626"></a>  assertFalse(goog.structs.some(col, f));
<a name="line627"></a>}
<a name="line628"></a>
<a name="line629"></a>function testSomeMap2() {
<a name="line630"></a>  var THIS_OBJ = {};
<a name="line631"></a>  var limit = 0;
<a name="line632"></a>  var col = new goog.structs.Map({a: 0, b: 1, c: 2});
<a name="line633"></a>  function f(v, key, col2) {
<a name="line634"></a>    assertEquals(col, col2);
<a name="line635"></a>    assertEquals(&#39;string&#39;, typeof key);
<a name="line636"></a>    assertEquals(THIS_OBJ, this);
<a name="line637"></a>    return v &gt; limit;
<a name="line638"></a>  }
<a name="line639"></a>  assertObjectEquals(true, goog.structs.some(col, f, THIS_OBJ));
<a name="line640"></a>  limit = 2;
<a name="line641"></a>  assertFalse(goog.structs.some(col, f, THIS_OBJ));
<a name="line642"></a>}
<a name="line643"></a>
<a name="line644"></a>function testSomeSet() {
<a name="line645"></a>  var limit = 0;
<a name="line646"></a>  var col = new goog.structs.Set([0, 1, 2]);
<a name="line647"></a>  function f(v, key, col2) {
<a name="line648"></a>    assertEquals(col, col2);
<a name="line649"></a>    assertEquals(&#39;undefined&#39;, typeof key);
<a name="line650"></a>    return v &gt; limit;
<a name="line651"></a>  }
<a name="line652"></a>  assertTrue(goog.structs.some(col, f));
<a name="line653"></a>  limit = 2;
<a name="line654"></a>  assertFalse(goog.structs.some(col, f));
<a name="line655"></a>}
<a name="line656"></a>
<a name="line657"></a>function testSomeSet2() {
<a name="line658"></a>  var THIS_OBJ = {};
<a name="line659"></a>  var limit = 0;
<a name="line660"></a>  var col = new goog.structs.Set([0, 1, 2]);
<a name="line661"></a>  function f(v, key, col2) {
<a name="line662"></a>    assertEquals(col, col2);
<a name="line663"></a>    assertEquals(&#39;undefined&#39;, typeof key);
<a name="line664"></a>    assertEquals(THIS_OBJ, this);
<a name="line665"></a>    return v &gt; limit;
<a name="line666"></a>  }
<a name="line667"></a>  assertTrue(goog.structs.some(col, f, THIS_OBJ));
<a name="line668"></a>  limit = 2;
<a name="line669"></a>  assertFalse(goog.structs.some(col, f, THIS_OBJ));
<a name="line670"></a>}
<a name="line671"></a>
<a name="line672"></a>function testSomeNodeList() {
<a name="line673"></a>  var tagName = &#39;P&#39;;
<a name="line674"></a>  var col = getAll();
<a name="line675"></a>  function f(v, i, col2) {
<a name="line676"></a>    assertEquals(col, col2);
<a name="line677"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line678"></a>    return v.tagName == tagName;
<a name="line679"></a>  }
<a name="line680"></a>  assertTrue(goog.structs.some(col, f));
<a name="line681"></a>  tagName = &#39;MARQUEE&#39;;
<a name="line682"></a>  assertFalse(goog.structs.some(col, f));
<a name="line683"></a>}
<a name="line684"></a>
<a name="line685"></a>function testSomeNodeList2() {
<a name="line686"></a>  var THIS_OBJ = {};
<a name="line687"></a>  var tagName = &#39;P&#39;;
<a name="line688"></a>  var col = getAll();
<a name="line689"></a>  function f(v, i, col2) {
<a name="line690"></a>    assertEquals(col, col2);
<a name="line691"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line692"></a>    assertEquals(THIS_OBJ, this);
<a name="line693"></a>    return v.tagName == tagName;
<a name="line694"></a>  }
<a name="line695"></a>  assertTrue(goog.structs.some(col, f, THIS_OBJ));
<a name="line696"></a>  tagName = &#39;MARQUEE&#39;;
<a name="line697"></a>  assertFalse(goog.structs.some(col, f, THIS_OBJ));
<a name="line698"></a>}
<a name="line699"></a>
<a name="line700"></a>// Every
<a name="line701"></a>
<a name="line702"></a>function testEvery() {
<a name="line703"></a>  var RV = {};
<a name="line704"></a>  var obj = {
<a name="line705"></a>    every: function(g) {
<a name="line706"></a>      assertEquals(f, g);
<a name="line707"></a>      assertEquals(this, obj);
<a name="line708"></a>      return RV;
<a name="line709"></a>    }
<a name="line710"></a>  };
<a name="line711"></a>  function f() {}
<a name="line712"></a>  assertEquals(RV, goog.structs.every(obj, f));
<a name="line713"></a>}
<a name="line714"></a>
<a name="line715"></a>function testEvery2() {
<a name="line716"></a>  var THIS_OBJ = {};
<a name="line717"></a>  var RV = {};
<a name="line718"></a>  var obj = {
<a name="line719"></a>    every: function(g, obj2) {
<a name="line720"></a>      assertEquals(f, g);
<a name="line721"></a>      assertEquals(this, obj);
<a name="line722"></a>      assertEquals(THIS_OBJ, obj2);
<a name="line723"></a>      return RV;
<a name="line724"></a>    }
<a name="line725"></a>  };
<a name="line726"></a>  function f() {}
<a name="line727"></a>  assertEquals(RV, goog.structs.every(obj, f, THIS_OBJ));
<a name="line728"></a>}
<a name="line729"></a>
<a name="line730"></a>function testEveryArrayLike() {
<a name="line731"></a>  var limit = -1;
<a name="line732"></a>  var col = [0, 1, 2];
<a name="line733"></a>  function f(v, i, col2) {
<a name="line734"></a>    assertEquals(col, col2);
<a name="line735"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line736"></a>    return v &gt; limit;
<a name="line737"></a>  }
<a name="line738"></a>  assertTrue(goog.structs.every(col, f));
<a name="line739"></a>  limit = 1;
<a name="line740"></a>  assertFalse(goog.structs.every(col, f));
<a name="line741"></a>}
<a name="line742"></a>
<a name="line743"></a>function testEveryArrayLike2() {
<a name="line744"></a>  var THIS_OBJ = {};
<a name="line745"></a>  var limit = -1;
<a name="line746"></a>  var col = [0, 1, 2];
<a name="line747"></a>  function f(v, i, col2) {
<a name="line748"></a>    assertEquals(col, col2);
<a name="line749"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line750"></a>    assertEquals(THIS_OBJ, this);
<a name="line751"></a>    return v &gt; limit;
<a name="line752"></a>  }
<a name="line753"></a>  assertTrue(goog.structs.every(col, f, THIS_OBJ));
<a name="line754"></a>  limit = 1;
<a name="line755"></a>  assertFalse(goog.structs.every(col, f, THIS_OBJ));
<a name="line756"></a>}
<a name="line757"></a>
<a name="line758"></a>function testEveryString() {
<a name="line759"></a>  var limit = -1;
<a name="line760"></a>  var col = &#39;012&#39;;
<a name="line761"></a>  function f(v, i, col2) {
<a name="line762"></a>    // for some reason the strings are equal but identical???
<a name="line763"></a>    assertEquals(String(col), String(col2));
<a name="line764"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line765"></a>    return Number(v) &gt; limit;
<a name="line766"></a>  }
<a name="line767"></a>  assertTrue(goog.structs.every(col, f));
<a name="line768"></a>  limit = 1;
<a name="line769"></a>  assertFalse(goog.structs.every(col, f));
<a name="line770"></a>}
<a name="line771"></a>
<a name="line772"></a>function testEveryString2() {
<a name="line773"></a>  var THIS_OBJ = {};
<a name="line774"></a>  var limit = -1;
<a name="line775"></a>  var col = &#39;012&#39;;
<a name="line776"></a>  function f(v, i, col2) {
<a name="line777"></a>    // for some reason the strings are equal but identical???
<a name="line778"></a>    assertEquals(String(col), String(col2));
<a name="line779"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line780"></a>    assertEquals(THIS_OBJ, this);
<a name="line781"></a>    return Number(v) &gt; limit;
<a name="line782"></a>  }
<a name="line783"></a>  assertTrue(goog.structs.every(col, f, THIS_OBJ));
<a name="line784"></a>  limit = 1;
<a name="line785"></a>  assertFalse(goog.structs.every(col, f, THIS_OBJ));
<a name="line786"></a>}
<a name="line787"></a>
<a name="line788"></a>function testEveryMap() {
<a name="line789"></a>  var limit = -1;
<a name="line790"></a>  var col = new goog.structs.Map({a: 0, b: 1, c: 2});
<a name="line791"></a>  function f(v, key, col2) {
<a name="line792"></a>    assertEquals(col, col2);
<a name="line793"></a>    assertEquals(&#39;string&#39;, typeof key);
<a name="line794"></a>    return v &gt; limit;
<a name="line795"></a>  }
<a name="line796"></a>  assertObjectEquals(true, goog.structs.every(col, f));
<a name="line797"></a>  limit = 1;
<a name="line798"></a>  assertFalse(goog.structs.every(col, f));
<a name="line799"></a>}
<a name="line800"></a>
<a name="line801"></a>function testEveryMap2() {
<a name="line802"></a>  var THIS_OBJ = {};
<a name="line803"></a>  var limit = -1;
<a name="line804"></a>  var col = new goog.structs.Map({a: 0, b: 1, c: 2});
<a name="line805"></a>  function f(v, key, col2) {
<a name="line806"></a>    assertEquals(col, col2);
<a name="line807"></a>    assertEquals(&#39;string&#39;, typeof key);
<a name="line808"></a>    assertEquals(THIS_OBJ, this);
<a name="line809"></a>    return v &gt; limit;
<a name="line810"></a>  }
<a name="line811"></a>  assertObjectEquals(true, goog.structs.every(col, f, THIS_OBJ));
<a name="line812"></a>  limit = 1;
<a name="line813"></a>  assertFalse(goog.structs.every(col, f, THIS_OBJ));
<a name="line814"></a>}
<a name="line815"></a>
<a name="line816"></a>function testEverySet() {
<a name="line817"></a>  var limit = -1;
<a name="line818"></a>  var col = new goog.structs.Set([0, 1, 2]);
<a name="line819"></a>  function f(v, key, col2) {
<a name="line820"></a>    assertEquals(col, col2);
<a name="line821"></a>    assertEquals(&#39;undefined&#39;, typeof key);
<a name="line822"></a>    return v &gt; limit;
<a name="line823"></a>  }
<a name="line824"></a>  assertTrue(goog.structs.every(col, f));
<a name="line825"></a>  limit = 1;
<a name="line826"></a>  assertFalse(goog.structs.every(col, f));
<a name="line827"></a>}
<a name="line828"></a>
<a name="line829"></a>function testEverySet2() {
<a name="line830"></a>  var THIS_OBJ = {};
<a name="line831"></a>  var limit = -1;
<a name="line832"></a>  var col = new goog.structs.Set([0, 1, 2]);
<a name="line833"></a>  function f(v, key, col2) {
<a name="line834"></a>    assertEquals(col, col2);
<a name="line835"></a>    assertEquals(&#39;undefined&#39;, typeof key);
<a name="line836"></a>    assertEquals(THIS_OBJ, this);
<a name="line837"></a>    return v &gt; limit;
<a name="line838"></a>  }
<a name="line839"></a>  assertTrue(goog.structs.every(col, f, THIS_OBJ));
<a name="line840"></a>  limit = 1;
<a name="line841"></a>  assertFalse(goog.structs.every(col, f, THIS_OBJ));
<a name="line842"></a>}
<a name="line843"></a>
<a name="line844"></a>function testEveryNodeList() {
<a name="line845"></a>  var nodeType = 1; // ELEMENT
<a name="line846"></a>  var col = getAll();
<a name="line847"></a>  function f(v, i, col2) {
<a name="line848"></a>    assertEquals(col, col2);
<a name="line849"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line850"></a>    return v.nodeType == nodeType;
<a name="line851"></a>  }
<a name="line852"></a>  assertTrue(goog.structs.every(col, f));
<a name="line853"></a>  nodeType = 3; // TEXT
<a name="line854"></a>  assertFalse(goog.structs.every(col, f));
<a name="line855"></a>}
<a name="line856"></a>
<a name="line857"></a>function testEveryNodeList2() {
<a name="line858"></a>  var THIS_OBJ = {};
<a name="line859"></a>  var nodeType = 1; // ELEMENT
<a name="line860"></a>  var col = getAll();
<a name="line861"></a>  function f(v, i, col2) {
<a name="line862"></a>    assertEquals(col, col2);
<a name="line863"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line864"></a>    assertEquals(THIS_OBJ, this);
<a name="line865"></a>    return v.nodeType == nodeType;
<a name="line866"></a>  }
<a name="line867"></a>  assertTrue(goog.structs.every(col, f, THIS_OBJ));
<a name="line868"></a>  nodeType = 3; // TEXT
<a name="line869"></a>  assertFalse(goog.structs.every(col, f, THIS_OBJ));
<a name="line870"></a>}
<a name="line871"></a>
<a name="line872"></a>// For each
<a name="line873"></a>
<a name="line874"></a>function testForEach() {
<a name="line875"></a>  var called = false;
<a name="line876"></a>  var obj = {
<a name="line877"></a>    forEach: function(g) {
<a name="line878"></a>      assertEquals(f, g);
<a name="line879"></a>      assertEquals(this, obj);
<a name="line880"></a>      called = true;
<a name="line881"></a>    }
<a name="line882"></a>  };
<a name="line883"></a>  function f() {}
<a name="line884"></a>  goog.structs.forEach(obj, f);
<a name="line885"></a>  assertTrue(called);
<a name="line886"></a>}
<a name="line887"></a>
<a name="line888"></a>function testForEach2() {
<a name="line889"></a>  var called = false;
<a name="line890"></a>  var THIS_OBJ = {};
<a name="line891"></a>  var obj = {
<a name="line892"></a>    forEach: function(g, obj2) {
<a name="line893"></a>      assertEquals(f, g);
<a name="line894"></a>      assertEquals(this, obj);
<a name="line895"></a>      assertEquals(THIS_OBJ, obj2);
<a name="line896"></a>      called = true;
<a name="line897"></a>    }
<a name="line898"></a>  };
<a name="line899"></a>  function f() {}
<a name="line900"></a>  goog.structs.forEach(obj, f, THIS_OBJ);
<a name="line901"></a>  assertTrue(called);
<a name="line902"></a>}
<a name="line903"></a>
<a name="line904"></a>function testForEachArrayLike() {
<a name="line905"></a>  var col = [0, 1, 2];
<a name="line906"></a>  var values = [];
<a name="line907"></a>  function f(v, i, col2) {
<a name="line908"></a>    assertEquals(col, col2);
<a name="line909"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line910"></a>    values.push(v * v);
<a name="line911"></a>  }
<a name="line912"></a>  goog.structs.forEach(col, f);
<a name="line913"></a>  assertArrayEquals([0, 1, 4], values);
<a name="line914"></a>}
<a name="line915"></a>
<a name="line916"></a>function testForEachArrayLike2() {
<a name="line917"></a>  var THIS_OBJ = {};
<a name="line918"></a>  var col = [0, 1, 2];
<a name="line919"></a>  var values = [];
<a name="line920"></a>  function f(v, i, col2) {
<a name="line921"></a>    assertEquals(col, col2);
<a name="line922"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line923"></a>    assertEquals(THIS_OBJ, this);
<a name="line924"></a>    values.push(v * v);
<a name="line925"></a>  }
<a name="line926"></a>  goog.structs.forEach(col, f, THIS_OBJ);
<a name="line927"></a>  assertArrayEquals([0, 1, 4], values);
<a name="line928"></a>}
<a name="line929"></a>
<a name="line930"></a>function testForEachString() {
<a name="line931"></a>  var col = &#39;012&#39;;
<a name="line932"></a>  var values = [];
<a name="line933"></a>  function f(v, i, col2) {
<a name="line934"></a>    // for some reason the strings are equal but identical???
<a name="line935"></a>    assertEquals(String(col), String(col2));
<a name="line936"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line937"></a>    values.push(Number(v) * Number(v));
<a name="line938"></a>  }
<a name="line939"></a>  goog.structs.forEach(col, f);
<a name="line940"></a>  assertArrayEquals([0, 1, 4], values);
<a name="line941"></a>}
<a name="line942"></a>
<a name="line943"></a>function testForEachString2() {
<a name="line944"></a>  var THIS_OBJ = {};
<a name="line945"></a>  var col = &#39;012&#39;;
<a name="line946"></a>  var values = [];
<a name="line947"></a>  function f(v, i, col2) {
<a name="line948"></a>    // for some reason the strings are equal but identical???
<a name="line949"></a>    assertEquals(String(col), String(col2));
<a name="line950"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line951"></a>    assertEquals(THIS_OBJ, this);
<a name="line952"></a>    values.push(Number(v) * Number(v));
<a name="line953"></a>  }
<a name="line954"></a>  goog.structs.forEach(col, f, THIS_OBJ);
<a name="line955"></a>  assertArrayEquals([0, 1, 4], values);
<a name="line956"></a>}
<a name="line957"></a>
<a name="line958"></a>function testForEachMap() {
<a name="line959"></a>  var col = new goog.structs.Map({a: 0, b: 1, c: 2});
<a name="line960"></a>  var values = [];
<a name="line961"></a>  var keys = [];
<a name="line962"></a>  function f(v, key, col2) {
<a name="line963"></a>    assertEquals(col, col2);
<a name="line964"></a>    assertEquals(&#39;string&#39;, typeof key);
<a name="line965"></a>    values.push(v * v);
<a name="line966"></a>    keys.push(key);
<a name="line967"></a>  }
<a name="line968"></a>  goog.structs.forEach(col, f);
<a name="line969"></a>  assertArrayEquals([0, 1, 4], values);
<a name="line970"></a>  assertArrayEquals([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;], keys);
<a name="line971"></a>}
<a name="line972"></a>
<a name="line973"></a>function testForEachMap2() {
<a name="line974"></a>  var THIS_OBJ = {};
<a name="line975"></a>  var col = new goog.structs.Map({a: 0, b: 1, c: 2});
<a name="line976"></a>  var values = [];
<a name="line977"></a>  var keys = [];
<a name="line978"></a>  function f(v, key, col2) {
<a name="line979"></a>    assertEquals(col, col2);
<a name="line980"></a>    assertEquals(&#39;string&#39;, typeof key);
<a name="line981"></a>    assertEquals(THIS_OBJ, this);
<a name="line982"></a>    values.push(v * v);
<a name="line983"></a>    keys.push(key);
<a name="line984"></a>  }
<a name="line985"></a>  goog.structs.forEach(col, f, THIS_OBJ);
<a name="line986"></a>  assertArrayEquals([0, 1, 4], values);
<a name="line987"></a>  assertArrayEquals([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;], keys);
<a name="line988"></a>}
<a name="line989"></a>
<a name="line990"></a>function testForEachSet() {
<a name="line991"></a>  var col = new goog.structs.Set([0, 1, 2]);
<a name="line992"></a>  var values = [];
<a name="line993"></a>  function f(v, key, col2) {
<a name="line994"></a>    assertEquals(col, col2);
<a name="line995"></a>    assertEquals(&#39;undefined&#39;, typeof key);
<a name="line996"></a>    values.push(v * v);
<a name="line997"></a>  }
<a name="line998"></a>  goog.structs.forEach(col, f);
<a name="line999"></a>  assertArrayEquals([0, 1, 4], values);
<a name="line1000"></a>}
<a name="line1001"></a>
<a name="line1002"></a>function testForEachSet2() {
<a name="line1003"></a>  var THIS_OBJ = {};
<a name="line1004"></a>  var col = new goog.structs.Set([0, 1, 2]);
<a name="line1005"></a>  var values = [];
<a name="line1006"></a>  function f(v, key, col2) {
<a name="line1007"></a>    assertEquals(col, col2);
<a name="line1008"></a>    assertEquals(&#39;undefined&#39;, typeof key);
<a name="line1009"></a>    assertEquals(THIS_OBJ, this);
<a name="line1010"></a>    values.push(v * v);
<a name="line1011"></a>  }
<a name="line1012"></a>  goog.structs.forEach(col, f, THIS_OBJ);
<a name="line1013"></a>  assertArrayEquals([0, 1, 4], values);
<a name="line1014"></a>}
<a name="line1015"></a>
<a name="line1016"></a>function testForEachNodeList() {
<a name="line1017"></a>  var values = [];
<a name="line1018"></a>  var col = getAll();
<a name="line1019"></a>  function f(v, i, col2) {
<a name="line1020"></a>    assertEquals(col, col2);
<a name="line1021"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line1022"></a>    values.push(v.tagName);
<a name="line1023"></a>  }
<a name="line1024"></a>  goog.structs.forEach(col, f);
<a name="line1025"></a>  assertEquals(&#39;HRPPPPPPPPH1&#39;, values.join(&#39;&#39;));
<a name="line1026"></a>}
<a name="line1027"></a>
<a name="line1028"></a>function testForEachNodeList2() {
<a name="line1029"></a>  var THIS_OBJ = {};
<a name="line1030"></a>  var values = [];
<a name="line1031"></a>  var col = getAll();
<a name="line1032"></a>  function f(v, i, col2) {
<a name="line1033"></a>    assertEquals(col, col2);
<a name="line1034"></a>    assertEquals(&#39;number&#39;, typeof i);
<a name="line1035"></a>    assertEquals(THIS_OBJ, this);
<a name="line1036"></a>    values.push(v.tagName);
<a name="line1037"></a>  }
<a name="line1038"></a>  goog.structs.forEach(col, f, THIS_OBJ);
<a name="line1039"></a>  assertEquals(&#39;HRPPPPPPPPH1&#39;, values.join(&#39;&#39;));
<a name="line1040"></a>}
</pre>


</body>
</html>
